/*
 * BlackLightning.LauncherDialog
 * Andy Tidball
 * 
 * Project: Black Lightning
 * Copyright: GNU General Public License
 */

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using BlackLightning.Properties;

namespace BlackLightning {
	/// <summary>
	/// A dialog to display to the user to have them locate the Launcher.
	/// </summary>
	public partial class LauncherDialog : Form {
		// member data - controls
		private Label   lblMessage;
		private Label   lblTitle;
		private Label   lblPath;
		private TextBox txtPath;
		private Button  btnBrowse;
		private Button  btnOK;
		private Button  btnCancel;

		/// <summary>
		/// Creates a new LauncherDialog.
		/// </summary>
		public LauncherDialog() {
			InitializeComponent();
		}

		/// <summary>
		/// Initializes all of our controls.
		/// </summary>
		private void InitializeComponent() {
			// create our controls
			lblMessage = new Label();
			lblTitle   = new Label();
			lblPath    = new Label();
			txtPath    = new TextBox();
			btnBrowse  = new Button();
			btnOK      = new Button();
			btnCancel  = new Button();

			// suspend layout logic while we setup
			SuspendLayout();

			// lblTitle
			lblTitle.Font      = new Font("Microsoft Sans Serif", 18F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0)));
			lblTitle.Location  = new Point(10, 8);
			lblTitle.Name      = "lblTitle";
			lblTitle.Size      = new Size(356, 26);
			lblTitle.TabIndex  = 0;
			lblTitle.Text      = "Locate Simutronics Launcher";
			lblTitle.TextAlign = ContentAlignment.MiddleCenter;
			// lblMessage
			lblMessage.Location = new Point(12, 43);
			lblMessage.Name     = "lblMessage";
			lblMessage.Size     = new Size(354, 26);
			lblMessage.TabIndex = 1;
			lblMessage.Text     = "Black Lightning was unable to locate the Simutronics Launcher at the following location.  Please use the Browse button to locate the Launcher.";

			// lblPath
			lblPath.AutoSize = true;
			lblPath.Location = new Point(12, 84);
			lblPath.Name     = "lblPath";
			lblPath.Size     = new Size(80, 13);
			lblPath.TabIndex = 2;
			lblPath.Text     = "Launcher Path:";
			// txtPath
			txtPath.Location = new Point(98, 81);
			txtPath.Name     = "txtPath";
			txtPath.Size     = new Size(187, 20);
			txtPath.TabIndex = 3;
			// btnBrowse
			btnBrowse.Location = new Point(291, 81);
			btnBrowse.Name     = "btnBrowse";
			btnBrowse.Size     = new Size(75, 20);
			btnBrowse.TabIndex = 4;
			btnBrowse.Text     = "Browse";
			btnBrowse.Click   += btnBrowse_Click;

			// btnOK
			btnOK.Enabled  = false;
			btnOK.Location = new Point(110, 113);
			btnOK.Name     = "btnOK";
			btnOK.Size     = new Size(75, 23);
			btnOK.TabIndex = 5;
			btnOK.Text     = "OK";
			btnOK.Click   += btnOK_Click;
			// btnCancel
			btnCancel.Location = new Point(193, 113);
			btnCancel.Name     = "btnCancel";
			btnCancel.Size     = new Size(75, 23);
			btnCancel.TabIndex = 6;
			btnCancel.Text     = "Cancel";
			btnCancel.Click   += btnCancel_Click;
			
			// this
			this.AcceptButton        = btnOK;
			this.CancelButton        = btnCancel;
			this.AutoScaleDimensions = new SizeF(6F, 13F);
			this.AutoScaleMode       = AutoScaleMode.Font;
			this.ClientSize          = new Size(378, 148);
			this.FormBorderStyle     = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon                = Resources.BlackLightningIcon;
			this.Name                = "LauncherDialog";
			this.Text                = "Black Lightning";
			
			// add the controls to the form
			this.Controls.Add(btnCancel);
			this.Controls.Add(btnOK);
			this.Controls.Add(btnBrowse);
			this.Controls.Add(txtPath);
			this.Controls.Add(lblPath);
			this.Controls.Add(lblMessage);
			this.Controls.Add(lblTitle);

			// resume layout logic
			this.ResumeLayout(false);
			this.PerformLayout();
		}

		/// <summary>
		/// Gets or sets the launcher path displayed in the dialog.
		/// </summary>
		public string LauncherPath {
			get {
				return txtPath.Text;
			}
			set {
				txtPath.Text = value;
			}
		}

		/// <summary>
		/// Called when the Browse button is clicked.
		/// </summary>
		/// <param name="Sender">The Button that was clicked.</param>
		/// <param name="e">No arguments.</param>
		private void btnBrowse_Click(object Sender, EventArgs e) {
			OpenFileDialog OFD = new OpenFileDialog();
			OFD.FileName = txtPath.Text;
			OFD.Filter = "Simutronics Launcher (Launcher.exe)|Launcher.exe";
			if (OFD.ShowDialog() != DialogResult.OK) {
				return;
			}
			txtPath.Text = OFD.FileName;
			btnOK.Enabled = File.Exists(txtPath.Text);
		}

		/// <summary>
		/// Called when the OK button is clicked.
		/// </summary>
		/// <param name="Sender">The Button that was clicked.</param>
		/// <param name="e">No arguments.</param>
		private void btnOK_Click(object Sender, EventArgs e) {
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		/// <summary>
		/// Called when the Cancel button is clicked.
		/// </summary>
		/// <param name="Sender">The Button that was clicked.</param>
		/// <param name="e">No arguments.</param>
		private void btnCancel_Click(object Sender, EventArgs e) {
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}
	}
}